<?php

$memoryLimit = ini_get('memory_limit');
switch (true) {
    case false !== strpos($memoryLimit, 'K'):
        $memoryLimit = (int)$memoryLimit * 1024;
        break;
    case false !== strpos($memoryLimit, 'M'):
        $memoryLimit = (int)$memoryLimit * 1024 * 1024;
        break;
    default:
        $memoryLimit = (int)$memoryLimit;
}

if ($memoryLimit < 32 * 1024 * 1024) {
    echo "$memoryLimit is too small\n";
    exit(1);
}



include(PRODUCT_ROOT."/admin/plib/modules/pm.php");
define ('MODULE_NAME', 'clamav');
define ('SCRIPT_VERSION', 0.1);
define ('UPDATE_SERVER', 'extendplesk.com');
define ('WRAPPER','clamav');



$distro = exec("cat /etc/redhat-release | grep 6");
$distro1 = exec("cat /etc/redhat-release | grep 5");
// For RHEL6 and CentOS-6

if (!empty($distro)) {


	if (php_uname('m') == "x86_64" ) {

		//Lets Set the RHEL6 and CentOS-6 64bit packages
		$package0 = "http://pkgs.repoforge.org/clamav/clamav-db-0.97.7-1.el6.rf.x86_64.rpm";
		$package1 = "http://pkgs.repoforge.org/clamav/clamav-0.97.7-1.el6.rf.x86_64.rpm";
	} else {
     	//Lets Set the RHEL6 and CentOS-6 32bit packages
		$package0 = "http://pkgs.repoforge.org/clamav/clamav-db-0.97.7-1.el6.rf.i686.rpm";
		$package1 = "http://pkgs.repoforge.org/clamav/clamav-0.97.7-1.el6.rf.i686.rpm";
	}
} elseif (!empty($distro1)) {


		if (php_uname('m') == "x86_64") {

			//Lets Set the RHEL5 and CentOS-5 64bit packages
			$package0 = "http://pkgs.repoforge.org/clamav/clamav-db-0.97.7-1.el5.rf.x86_64.rpm";
			$package1 = "http://pkgs.repoforge.org/clamav/clamav-0.97.7-1.el5.rf.x86_64.rpm";
		} else {
			//Lets Set the RHEL5 and CentOS-5 32bit packages
			$package0 = "http://pkgs.repoforge.org/clamav/clamav-db-0.97.7-1.el5.rf.i386.rpm";
			$package1 = "http://pkgs.repoforge.org/clamav/clamav-0.97.7-1.el5.rf.i386.rpm";
		}
} else{
		
	echo "This Os is not supported yet.\n";
	exit(1);
	}


$args = " --install --file=";


//echo "starting db install ";
$output = exec(PRODUCT_ROOT."/admin/bin/modulemng".$args.$package0); 
//print_r($output);


//echo "starting core file install ";
$output = shell_exec(PRODUCT_ROOT."/admin/bin/modulemng".$args.$package1);
//print_r($output);

//Lets create our results table
pm_Bootstrap::getDbAdapter()->query("CREATE TABLE IF NOT EXISTS `clamav_logs` (
  `id` varchar(35) NOT NULL,
  `date` datetime NOT NULL,
  `results` longtext,
  `virus` tinyint(1) NOT NULL DEFAULT '0',
  `status` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  FULLTEXT KEY `results` (`results`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;");




exit(0);
